"use strict";
cc._RF.push(module, 'e320eQxvKZEAK8oKwYeEjf4', 'AddPrefabHelper');
// Script/Ssg/Helper/AddPrefabHelper.js

'use strict';

/**
 * 预制体UI的添加,移除操作的管理组件
 */

window.AddPrefabHelper = cc.Class({
    extends: cc.Component,

    properties: function properties() {
        return {};
    },

    statics: {

        createPrefab: function createPrefab(prefab) {
            var prefabNode = null;
            if (cc.supportJit) {
                cc.supportJit = false;
                prefabNode = cc.instantiate(prefab);
                cc.supportJit = true;
            } else {
                // 如果是特殊的不支持 JIT 的平台，则不需要优化，也不能强制设置 cc.supportJit 为 true
                prefabNode = cc.instantiate(prefab);
            }
            return prefabNode;
        },

        addPrefabUI: function addPrefabUI(url, parent, zOrder, callback) {
            AddPrefabHelper.addShieldNode();
            var self = this;
            UIHelper.loadRes(url, cc.Prefab, function (prefab) {
                var prefabUI = self.createPrefab(prefab);
                parent.addChild(prefabUI, zOrder);
                AddPrefabHelper.removeShieldNode();
                if (callback) {
                    callback(prefabUI);
                }
            });
        },

        //添加一个全屏屏蔽触摸的node
        addShieldNode: function addShieldNode(callback) {
            if (this.isHaveShieldNode()) {
                if (callback) {
                    callback(cc.director.getScene().getChildByName('shieldNode'));
                }
                return;
            }
            var winSize = cc.director.getWinSize();
            var shieldNode = new cc.Node('shieldNode');
            shieldNode.anchorX = 0;
            shieldNode.anchorY = 0;
            shieldNode.setContentSize(winSize);
            cc.director.getScene().addChild(shieldNode, 100000);
            shieldNode.on('touchstart', function (event) {
                event.stopPropagation();
                return false;
            });

            if (callback) {
                callback(shieldNode);
            }
        }
    }
});

module.exports = AddPrefabHelper;

cc._RF.pop();